home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group97a.txt
/
000032_icon-group-sender _Mon Feb 3 09:15:14 1997.msg
< prev
next >
Wrap
Internet Message Format
|
2000-09-20
|
3KB
Received: by cheltenham.cs.arizona.edu; Mon, 3 Feb 1997 13:13:23 MST
Date: Mon, 3 Feb 1997 09:15:14 -0700
From: swampler@noao.edu (Steve Wampler)
Subject: Re: Icon Tables
To: joan@cs.ucr.edu
Cc: icon-group@cs.arizona.edu
Message-Id: <swampler-9701031615.AA000714199@orpheus.gemini.edu>
In-Reply-To: <Pine.LNX.3.95.970202145856.27059A-100000@hill.ucr.edu>
Errors-To: icon-group-errors@cs.arizona.edu
Status: RO
Content-Length: 2227
Junrong Yuan wrote:
> Dear Sirs
>
> I have a question about Icon data structure of 'table'. As I
> understand it, a table is a 2D array that has a 'key', and a 'value', I
> wonder what kind of types that the 'value' field support. To be more
> specific, does it support 'record' or 'list'? The Icon book
> said it can be used to implement symbol tables, etc. In the case of symbol
> table, a key may correspond to several attributes, I am thinking of
> putting all the attributes in a record, but I couldn't find a way to store
> a record as 'value' filed in a table.
In Icon, any variable can hold a value of any type. This includes the entry
and value fields of tables, sets, records, lists, whatever. To put a record into
a table, just assign an instance of the record to a table entry. E.g:
record point(x,y,z)
.
.
.
t := table()
t["pos1"] := point(1.0,1.0,5.0)
Note that the record definition ("record point(x,y,z)") has to appear outside of
any procedure definition.
> Another question: does list support search functions? If I have
> a list of records, and I want to find a given item in the list that has a
> given value in a certain record field. What shall I do ?
If you are using Icon 9.3 and newer, there is a function sortf() that will sort
a list (or table) on the basis of field values of records in the list or table.
However, this does sort the entire list instead of searching it, so you would
still have to search the list.
It's easy to write code to generate all records in a list list of records that have
some value in a specific field, e.g.:
every (r := !a).z = 5.0 do {
# process record r from list a, since it has a z field value of 5.0...
...
}
or, if you actually need the list index value for some reason:
every i := 1 to *a do {
if a[i].z = 5.0 then {
# process record a[i]...
}
}
If you are always searching the same field each time, you might consider putting
the records into a table instead of a list, but this would take a bit more setup.
--
Steve Wampler - swampler@gemini.edu [Gemini 8m Telescopes Project (under AURA)]
The Gods that smiled upon your birth are laughing now. -- fortune cookie